package com.ny.dao.impl;

import com.ny.dao.ProductDao;
import com.ny.entity.Product;
import com.ny.until.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProductDaoImpl implements ProductDao {
    public DbUtil dbUtil=new DbUtil();

    @Override
    public List<Product> getAllProducts() throws SQLException {
        Connection connection = dbUtil.getCon();
        String sql = "select * from product";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        List<Product> products = new ArrayList<Product>();
        while (resultSet.next()) {
            int id = resultSet.getInt("product_id");
            String name = resultSet.getString("product_name");
            double price = resultSet.getDouble("price");
            int stock = resultSet.getInt("stock");
            String category = resultSet.getString("category");
            String description = resultSet.getString("description");
            Product product = new Product();
            product.setProductId(id);
            product.setProductName(name);
            product.setPrice(price);
            product.setStock(stock);
            product.setCategory(category);
            product.setDescription(description);
            products.add(product);
        }
        return null;
    }
}
